using Microsoft.AspNetCore.Mvc;
using ZR.Model.BaseManage.Dto;
using ZR.Model.BaseManage;
using ZR.Service.BaseManage.IBaseManageService;
using ZR.Admin.WebApi.Filters;

//创建时间：2025-04-22
namespace ZR.Admin.WebApi.Controllers.BaseManage
{
    /// <summary>
    /// plc信息
    /// </summary>
    [Verify]
    [Route("BaseManage/BasePlc")]
    public class BasePlcController : BaseController
    {
        /// <summary>
        /// plc信息接口
        /// </summary>
        private readonly IBasePlcService _BasePlcService;

        public BasePlcController(IBasePlcService BasePlcService)
        {
            _BasePlcService = BasePlcService;
        }

        /// <summary>
        /// 查询plc信息列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("pageList")]
        [ActionPermissionFilter(Permission = "base:plc:list")]
        public IActionResult PageBasePlc([FromQuery] BasePlcQueryDto parm)
        {
            var response = _BasePlcService.GetPageList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询plc信息列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "base:plc:list")]
        public IActionResult ListBasePlc([FromQuery] BasePlcQueryDto parm)
        {
            var response = _BasePlcService.GetList(parm);
            return SUCCESS(response);
        }


        /// <summary>
        /// 查询plc信息详情
        /// </summary>
        /// <param name="PlcCode"></param>
        /// <returns></returns>
        [HttpGet("{PlcCode}")]
        [ActionPermissionFilter(Permission = "base:plc:query")]
        public IActionResult GetBasePlc(string PlcCode)
        {
            var response = _BasePlcService.GetInfo(PlcCode);
            
            var info = response.Adapt<BasePlcDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加plc信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "base:plc:add")]
        [Log(Title = "plc信息", BusinessType = BusinessType.INSERT)]
        public IActionResult AddBasePlc([FromBody] BasePlcDto parm)
        {
            var modal = parm.Adapt<BasePlc>().ToCreate(HttpContext);

            var response = _BasePlcService.AddBasePlc(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新plc信息
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "base:plc:edit")]
        [Log(Title = "plc信息", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateBasePlc([FromBody] BasePlcDto parm)
        {
            var modal = parm.Adapt<BasePlc>().ToUpdate(HttpContext);
            var response = _BasePlcService.UpdateBasePlc(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除plc信息
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete")]
        [ActionPermissionFilter(Permission = "base:plc:delete")]
        [Log(Title = "plc信息", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteBasePlc([FromBody] string[] ids)
        {
            return ToResponse(_BasePlcService.Delete(ids));
        }

    }
}